﻿using System.Collections;
using System.Text;
using System.Web;
using System.Web.SessionState;

namespace CY_MVC.HttpHandlers
{
    public abstract class BaseController : IHttpHandler, IRequiresSessionState
    {
        protected abstract void Page_Load();

        #region protected变量

        protected IDictionary Items;
        protected HttpRequest Request;
        protected HttpResponse Response;
        protected HttpSessionState Session;
        protected int CacheSeconds;

        #endregion

        #region protected函数

        protected bool IsPostBack
        {
            get { return string.CompareOrdinal(Request.HttpMethod, "POST") == 0; }
        }

        #endregion

        #region private函数

        protected void Init(HttpContext p_Context)
        {
            Items = p_Context.Items;
            Request = p_Context.Request;
            Response = p_Context.Response;
            Session = p_Context.Session;

            //默认下发类型为html页面
            Response.ContentType = "text/html;charset=utf-8";
            Response.ContentEncoding = Encoding.UTF8;
            Response.Charset = "utf-8";
        }

        #endregion

        public virtual void ProcessRequest(HttpContext p_Context)
        {
            Init(p_Context);

            Page_Load();
        }

        public bool IsReusable
        {
            get { return false; }
        }
    }
}
